<template>
  <div class="customer-service" @click="openCustomerService">
    <img src="/img/line.jpg" alt="在线客服" class="customer-service-icon">
    <div class="customer-service-text">
オンラインサポート</div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { commonApi } from '../api/index'

// 应用配置数据
const appConfig = ref({
  name: 'WorkMatch',
  cz_jrjg: '',
  cz_fhmc: '',
  cz_fhbh: '',
  cz_jylx: '',
  cz_zhmgh: '',
  cz_jmzy: '',
  cz_myhz: '',
  kefu: ''
})

// 获取应用配置
const getAppConfig = async () => {
  try {
    const res = await commonApi.getAppConfig()
    if (res.code === 1 && res.data) {
      appConfig.value = res.data
      console.log('应用配置已获取', appConfig.value)
    }
  } catch (error) {
    console.error('获取应用配置失败:', error)
  }
}

// 打开客服页面
const openCustomerService = () => {
  if (appConfig.value.kefu) {
    window.open(appConfig.value.kefu, '_blank')
  } else {
    ElMessage.warning('客服链接不可用')
  }
}

// 组件挂载时获取应用配置
onMounted(() => {
  getAppConfig()
})
</script>

<style scoped>
/* 在线客服组件样式 */
.customer-service {
  position: fixed;
  right: 0;
  top: 70%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  z-index: 999;
  background-color: #fff;
  padding: 10px 5px;
  border-radius: 10px 0 0 10px;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.customer-service:hover {
  transform: translateY(-50%) translateX(-5px);
}

.customer-service-icon {
  width: 32px;
  height: 32px;
  padding: 2px;
  margin-bottom: 10px;
}

.customer-service-text {
  font-size: 16px;
  color: #0066cc;
  writing-mode: vertical-lr;
  text-orientation: upright;
  letter-spacing: 2px;
  font-weight: 700;
}

@media screen and (max-width: 768px) {
  .customer-service {
    padding: 8px 3px;
  }
  
  .customer-service-icon {
    width: 30px;
    height: 30px;
  }
  
  .customer-service-text {
    font-size: 10px;
    letter-spacing: 1px;
  }
}
</style>